package com.example.stuasist;

import java.util.List;

import com.example.stuasist.R;
import com.example.stuasist.db.stuasistDbOpenHelper;
import com.example.stuasist.db.dao.CourseDao;
import com.example.stuasist.domain.Course;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.app.Activity;
import android.content.Intent;

public class information extends Activity implements OnClickListener{
	private Button information_bt_return = null;
	private Button information_bt_edit;
	private TextView CNTextView;
	private TextView CTTextView;
	private TextView CRTextView;
	private TextView TerTextView;
	private TextView WeekTextView;
	private LayoutInflater inflater;
	private ListView listView;
	private List<Course> courses;
	private Course courseNow;
	
	String T_week_day;//周几的课
	int T_day_no;//第几节课

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);   //去掉标题栏
		super.setContentView(R.layout.information);
		this.CNTextView =  (TextView) findViewById(R.id.information_et_cname);
		this.CTTextView =  (TextView) findViewById(R.id.information_et_ctime);
		this.CRTextView =  (TextView) findViewById(R.id.information_et_croom);
		this.TerTextView =  (TextView) findViewById(R.id.information_et_teacher);
		this.WeekTextView = (TextView) findViewById(R.id.information_et_cweek);
		information_bt_return = (Button) findViewById(R.id.information_bt_return);
		information_bt_edit = (Button) findViewById(R.id.information_bt_edit);
		
		this.information_bt_return.setOnClickListener(this);
		this.information_bt_edit.setOnClickListener(this);
		
		stuasistDbOpenHelper helper = new stuasistDbOpenHelper(this);
		
		helper.getReadableDatabase();
		
		CourseDao dao = new CourseDao(this);
		
		courses = dao.getAllCourses();
		
		Intent intent = getIntent();
		T_week_day = intent.getStringExtra("T_week_day");
		T_day_no = intent.getIntExtra("T_day_no",-1);
		//System.out.println("T_week_day = " + T_week_day);
		//System.out.println("T_day_no = " + T_day_no);
		
		int len = courses.size();
		for(int i = 0; i < len; i++){
			Course cource = courses.get(i);
			int row = cource.getDay_no();
			String col = cource.getWeek_day();
			if(row ==T_day_no && col.equals(T_week_day)){

				courseNow = cource;
			}
		}
		
		CNTextView.setText(courseNow.getCourse_name());
		CTTextView.setText(courseNow.getTime_detil());
		CRTextView.setText(courseNow.getClassroom());
		TerTextView.setText(courseNow.getTeacher_name());
		WeekTextView.setText(courseNow.getWeeks());
		

	}
	
	



	@Override
	protected void onResume() {
		super.onResume();
		
		CourseDao dao = new CourseDao(this);
		
		courses = dao.getAllCourses();
		
		Intent intent = getIntent();
		T_week_day = intent.getStringExtra("T_week_day");
		T_day_no = intent.getIntExtra("T_day_no",-1);
		//System.out.println("T_week_day = " + T_week_day);
		//System.out.println("T_day_no = " + T_day_no);
		
		int len = courses.size();
		for(int i = 0; i < len; i++){
			Course cource = courses.get(i);
			int row = cource.getDay_no();
			String col = cource.getWeek_day();
			if(row ==T_day_no && col.equals(T_week_day)){

				courseNow = cource;
			}
		}
		
		CNTextView.setText(courseNow.getCourse_name());
		CTTextView.setText(courseNow.getTime_detil());
		CRTextView.setText(courseNow.getClassroom());
		TerTextView.setText(courseNow.getTeacher_name());
		WeekTextView.setText(courseNow.getWeeks());
	}





	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {
		case R.id.information_bt_return:
			intent = new Intent(information.this, MainActivity.class);   //实现页面跳转
			startActivity(intent);
			
			break;
		case R.id.information_bt_edit:
			
			intent = new Intent(information.this, information_edit.class);   //实现页面跳转
			intent.putExtra("T_to_info_edit_course_name", CNTextView.getText());
			intent.putExtra("T_to_info_edit_time_detil", CTTextView.getText());
			intent.putExtra("T_to_info_edit_classroom", CRTextView.getText());
			intent.putExtra("T_to_info_edit_teacher_name", TerTextView.getText());
			intent.putExtra("T_to_info_edit_weeks", WeekTextView.getText());
			intent.putExtra("T_to_info_edit_day_no", T_day_no);
			intent.putExtra("T_to_info_edit_week_day", T_week_day);
			
			startActivity(intent);
			
			break;

	
		}
		
	}
}